package com.zcs.thread.created;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * @author zcs
 * @since 2023/4/24
 */
public class MyCallable {


    public static void main(String[] args) {
        FutureTask<Integer> future = new FutureTask<>(new ThreadA());
        //实质上还是以Callable对象来创建并启动线程
        new Thread(future, "有返回值的线程").start();
        //get()方法会阻塞，直到子线程执行结束才返回
        try {
            System.out.println("子线程的返回值：" + future.get());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    static class ThreadA implements Callable<Integer> {

        @Override
        public Integer call() {
            return 15 + 16;
        }
    }

}
